package main

import (
	"fmt"
	"log"
)

func main() {
	A := []uint64{100001, 100002, 100003, 100004}
	B := []uint64{100002, 100003, 100004, 100005}
	C := []uint64{100003, 100004, 100005, 100006}
	D := []uint64{100004, 100005, 100006, 100007}
	fmt.Println(SliceIntersectUint64(A, B, C, D))
	log.Fatal()
}

func SliceIntersectUint64(sliceA []uint64, sliceB []uint64, moreSlice ...[]uint64) (sliceRet []uint64) {
	if len(moreSlice) == 0 {
		mapA := make(map[uint64]struct{}, len(sliceA))
		mapB := make(map[uint64]struct{}, len(sliceB))
		for _, v := range sliceA {
			mapA[v] = struct{}{}
		}
		for _, v := range sliceB {
			if _, exists := mapA[v]; exists {
				lenOri := len(mapB)
				mapB[v] = struct{}{}
				if len(mapB) > lenOri {
					sliceRet = append(sliceRet, v)
				}
			}
		}
		return
	}
	return SliceIntersectUint64(SliceIntersectUint64(sliceA, moreSlice[0]), sliceB, moreSlice[1:]...)

}
